package cz.apnetis.fitweb.shared.dto;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.gwt.user.client.rpc.IsSerializable;

import cz.apnetis.fitweb.shared.Calorie;

@PersistenceCapable
public class CalorieEntity implements Calorie, IsSerializable {

  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
  private String key;
  @Extension(vendorName="datanucleus", key="gae.pk-name", value="true")
  private String keyName;
  @Persistent
//  @Extension(vendorName="datanucleus", key="gae.pk-name", value="true")
  private String name;
/*  private String keyName;
  @Persistent
  @Extension(vendorName="datanucleus", key="gae.pk-id", value="true")
  private Long keyId;
    */
  @Persistent
  private Integer cal;
  @Persistent
  private Integer joule;

  @Override public String getKey() { return key; }
  @Override public void setKey(String newKey) { this.key = newKey; }

  public final String getKeyName() { return keyName; }
  public final void setKeyName(final String keyName) { this.keyName = keyName; }

  @Override public String getName() { return name; }
  @Override public void setName(String newName) { this.name = newName; }

  @Override public Integer getCal() { return cal; }
  @Override public void setCal(Integer newCal) { this.cal = newCal; }

  @Override public Integer getJoule() { return this.joule; }
  @Override public void setJoule(Integer newJoule) { this.joule = newJoule; }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result
        + ((key == null) ? 0 : key.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    CalorieEntity other = (CalorieEntity) obj;
    if (key == null) {
      if (other.key != null) {
        return false;
      }
    } else if (!key.equals(other.key)) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return getKey() + "|" + getName() + "|" + String.valueOf(getCal())
      + "|" + String.valueOf(getJoule());
  }
}
